package io.bluefw.blueui.dsl.render.widget;

import org.eclipse.jetty.util.StringUtil;

import io.bluefw.blueui.dsl.Widget;

public class WidgetRenderBuilder {
	public static WidgetRender build(Widget widget) {
		WidgetRender wr = null;
		if (StringUtil.isBlank(widget.getType())) {
			wr = buildDefaultWidgetRender(widget);
		}
		return wr;
	}
	
	private static WidgetRender buildDefaultWidgetRender(Widget widget) {
		WidgetRender wr = null;
		Class<?> clazz = widget.getEntity().getFieldType(widget.getBinding());
		if (clazz.equals(String.class)) {
			wr = new TextBoxWidget(widget);
		} else if (clazz.isEnum()) {
			wr = new ComboBoxWidget(widget);
		} else if (clazz.equals(int.class)) {
			wr = new NumberBoxWidget(widget);
			widget.getProps().putIfAbsent("decimalDigits", 0);
		}
		return wr;
	}
}
